(function () {
    require.config({
        paths: {
            vue: 'vue',
            text: 'text',
            titletemp: '../html/detail_segments/title.html',
            media1temp: '../html/detail_segments/media1.html',
            articletemp: '../html/detail_segments/article.html',
            media2temp: '../html/detail_segments/media2.html',
            commenttemp: '../html/detail_segments/comment.html',
            optionstemp: '../html/detail_segments/options.html',
            bottomtemp: '../html/detail_segments/bottom.html',
            speaktemp: '../html/detail_segments/speak.html',
            replystemp: '../html/detail_segments/replys.html'
        }
    });
    define(['vue', 'text!titletemp', 'text!media1temp', 'text!articletemp', 'text!media2temp', 'text!commenttemp', 'text!optionstemp', 'text!bottomtemp', 'text!speaktemp', 'text!replystemp'], function (Vue, Title, Media1, Article, Media2, Comment, Options, Bottom, Speak, Reply) {
        var detWrap = document.getElementById('today-detail');
        //标题部分
        Vue.component('news-title', {
            props: ["newstitle"],
            template: Title
        });
        //上作者部分
        Vue.component('media-h', {
            props: ['media_avatar', 'media_name', 'verify_status', 'time', 'care_status'],
            template: Media1,
            computed: {
                care_text: function () {
                    if (this.care_status === 0) {
                        return '关注';
                    }
                    else if (this.care_status === 1) {
                        return '已关注';
                    }
                }
            },
        });
        //正文部分
        Vue.component('main-art', {
            props: ["newstemp"],
            template: Article,
        });
        //下作者部分
        Vue.component('media-h2', {
            props: ['media_avatar', 'media_name', 'verify_status', 'media_desc', 'care_status'],
            template: Media2,
            computed: {
                care_text: function () {
                    if (this.care_status === 0) {
                        return '关注';
                    }
                    else if (this.care_status === 1) {
                        return '已关注';
                    }
                }
            },
        });
        //评论列表
        Vue.component('comment-zone', {
            template: Comment,
            data: function () {
                return {
                    comments: []
                }
            },
            methods: {
                update: function () {
                    this.comments = [
                        {
                            id: 1,
                            avatar: 'http://p1.pstatp.com/thumb/18a2000e5b81ec1a1185',
                            nick: '听见冬天里的离别',
                            likes: 2387,
                            text: '出去的时候20多岁，在外面呆了23年，现在40多岁了，正是科研年富力强出成果的时候，欢迎回来！！',
                            time: '04-24 22:06',
                            replys: 30
                        },
                        {
                            id: 2,
                            avatar: 'http://p1.pstatp.com/thumb/1bf300056d0f2f658c25',
                            nick: '风景这边独好',
                            likes: 4133,
                            text: '美国为什么那么强大呀？它就是靠着这样数以万计的锦上添花强大起来的，要走强国之路，就一定要有包容人才的心胸和为得到人才的那种强烈欲望。',
                            time: '04-24 22:06',
                            replys: 75
                        }
                    ];
                },
                todet: function (comm_id) {
                    this.$emit('opendet', { review_id: comm_id });
                }
            },
            mounted: function () {
                this.update();
            }
        });
        //弹出层部分
        Vue.component('over-layer', {
            props: ['optshow', 'media_avatar'],
            template: Options,
            data: function () {
                return {
                    options: [
                        {
                            type: 0,
                            title: '微信朋友圈'
                        },
                        {
                            type: 0,
                            title: '微信好友'
                        },
                        {
                            type: 0,
                            title: 'QQ好友'
                        },
                        {
                            type: 0,
                            title: 'QQ空间'
                        },
                        {
                            type: 1,
                            title: '查看头条号'
                        },
                        {
                            type: 0,
                            title: '夜间模式'
                        },
                        {
                            type: 0,
                            title: '显示设置'
                        },
                        {
                            type: 0,
                            title: '举报'
                        }
                    ]
                }
            },
            methods: {
                closeover: function () {
                    this.$emit('optchange');
                }
            },
            mounted: function () { }
        });
        //底部操作区
        Vue.component('bot-opt', {
            props: ['comm_num'],
            template: Bottom,
            methods: {
                togwrite: function () {
                    this.$emit('tog-write');
                },
                //转到评论区
                gotocomm: function () {
                    var el = document.getElementById('comm-sec');
                    el.scrollIntoView(true);
                },
                //点击收藏
                favorite: function () {
                    console.log('点击收藏成功');
                },
                //点击分享
                share: function () {
                    this.$emit('optchange');
                }
            }
        });
        //评论发表
        Vue.component('comm-pop', {
            props: ['comm_show'],
            template: Speak,
            data: function () {
                return {
                    comm_text: ''
                }
            },
            methods: {
                togwrite: function () {
                    this.$emit('tog-write');
                },
                submit_comm: function () {
                    if (!this.comm_text.trim()) {
                        console.log('提交评论不能为空');
                    }
                    else {
                        var xhr = new XMLHttpRequest();
                        xhr.open('POST', 'http://www.google.co.jp');
                        xhr.onload = function () {
                            console.log('评论提交成功');
                            this.togwrite();
                        }
                        xhr.send({ comm_text: this.comm_text });
                    }
                }
            }
        });
        //评论详情
        Vue.component('replys', {
            props: ['replyon', 'replyid'],
            template: Reply,
            data: function () {
                return {
                    id: null,
                    useracc: null,
                    avatar: '',
                    nick: '',
                    likes: 0,
                    text: '',
                    time: '',
                    zans: [],
                    replys: []
                }
            },
            methods: {
                update: function (revid) {
                    //这里用reviewid去请求评论详情,并更改结果,这里示例直接更改结果
                    this.id = revid;
                    this.useracc = 136268538;
                    this.avatar = 'http://p1.pstatp.com/thumb/18a2000e5b81ec1a1185';
                    this.nick = '听见冬天里的离别';
                    this.likes = 2387;
                    this.text = '出去的时候20多岁，在外面呆了23年，现在40多岁了，正是科研年富力强出成果的时候，欢迎回来！！';
                    this.time = '05-10 22:06';
                    this.zans = [
                        {
                            id: 1,
                            useracc: 136268538,
                            avatar: 'http://p3.pstatp.com/thumb/16ab000088c775720ee5',
                        },
                        {
                            id: 2,
                            useracc: 136268538,
                            avatar: 'http://p9.pstatp.com/thumb/1dcb0021cdc808ace7b4'
                        },
                        {
                            id: 3,
                            useracc: 136268538,
                            avatar: 'http://p3.pstatp.com/thumb/1dce0004569c19013cfe'
                        },
                        {
                            id: 4,
                            useracc: 136268538,
                            avatar: 'http://p3.pstatp.com/thumb/135300016e4ca3b66bc4'
                        },
                        {
                            id: 5,
                            useracc: 136268538,
                            avatar: 'http://p3.pstatp.com/thumb/ef50018068534a6db4e'
                        }
                    ];
                    this.replys = [
                        {
                            id: 1,
                            useracc: 3698563256,
                            avatar: 'http://p1.pstatp.com/thumb/1504/6908143554',
                            nick: '8戒de肚',
                            likes: 9,
                            text: '说得好',
                            time: '05-10 22:06'
                        },
                        {
                            id: 2,
                            useracc: 6536522,
                            avatar: 'http://p3.pstatp.com/thumb/1dcb00098016a17e0ba1',
                            nick: '萌萌哒哒bbk2269',
                            likes: 5,
                            text: '这他么不就是我。',
                            time: '3天前'
                        },
                        {
                            id: 3,
                            useracc: 784463354,
                            avatar: 'http://p1.pstatp.com/thumb/1bf7000424f2bba1b0b4',
                            nick: '宇文世平',
                            likes: 3,
                            text: '这不是在说我吗？',
                            time: '5天前'
                        }
                    ];
                },
                close: function () {
                    this.$emit('closedet');
                    this.id = null;
                    this.useracc = null;
                    this.avatar = '';
                    this.nick = '';
                    this.likes = 0;
                    this.text = '正在加载中...';
                    this.time = '';
                    this.zans = [];
                    this.replys = [];
                }
            },
            watch: {
                replyid: function (reviewid) {
                    if (!reviewid) {
                        return;
                    }
                    else {
                        this.update(reviewid);
                    }
                }
            }
        });
        new Vue({
            el: detWrap,
            data: function () {
                return {
                    title: '',
                    media_avatar: '',
                    media_name: '',
                    verify_status: null,
                    media_desc: '',
                    time: '',
                    care_status: null,
                    article: '',
                    comm_number: null,
                    options_show: false,
                    comm_show: false,
                    reply_show: false,
                    reply_id: null
                }
            },
            methods: {
                togover: function () {
                    this.options_show = !this.options_show;
                },
                togwrite: function () {
                    this.comm_show = !this.comm_show;
                },
                togreply: function (reviewid) {
                    this.reply_id = reviewid;
                    this.reply_show = !this.reply_show;
                }
            },
            updated: function () {
                if (this.comm_show === true) {
                    document.getElementById('write-content').focus();
                }
            },
            mounted: function () {
                this.title = '巨大冰山漂至加拿大沿海小镇民众争相"看山"(图)';
                this.media_avatar = 'http://p3.pstatp.com/large/97d001bf3f3cba72913';
                this.media_name = '中国新闻网';
                this.verify_status = 1;
                this.media_desc = '中新网是全球中文互联网原创新闻报道最重要的内容供应者。';
                this.time = '2017-04-19 12:00:00';
                this.care_status = 0;
                this.comm_number = 533;
                this.article = '<p><video width="100%" controls><source src="../img/yangmi.mp4" type="video/mp4">Your browser does not support the video tag.</video></p><p>中新网4月20日电 据外媒报道，日前，在加拿大纽芬兰省南岸，一座巨大的冰山慢慢漂浮而至，吸引了不少人前去“看山”。</p><p><img src="http://wx3.sinaimg.cn/mw1024/473df571ly1fesyo1d21ij23vc2kxx6s.jpg" /></p><p>据报道，小镇Ferryland是观赏这座冰山的最佳地点。有当地居民称，这座冰山高40多米，大概是当地目前为止见到的最大的一座冰山，而且这座冰山在16日漂到当地后，就基本上不动了。</p><p><img src="http://wx4.sinaimg.cn/mw1024/473df571ly1fe3xtlj8t0j211i1e04qp.jpg" /></p><p>Ferryland镇长阿德里安•卡瓦纳(Adrian Kavanagh)表示，这座冰山从周边地区吸引来大量好奇的人们。为了看冰山，有人开车一个多小时来到此地。</p><p>据介绍，冰山观光一直是纽芬兰省旅游业的重点项目之一，当地的旅游公司会用船把游客带到冰山附近进行近距离观赏。</p><p>阿德里安•卡瓦纳说，今年的冰山季开始得早，如果风速加大，将会把更多的冰山带到Ferryland，在晴朗的日子里，远处往往可以看见好几座大冰山的“身影”。</p>';
            }
        });
    });
})();

